package com.zeros.myfestec;

import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.view.View;
import android.widget.Toast;

import com.zeros.latte.delegates.LatteDelegate;
import com.zeros.latte.net.RestClient;
import com.zeros.latte.net.callback.IError;
import com.zeros.latte.net.callback.IFailure;
import com.zeros.latte.net.callback.ISuccess;

/**
 * 实现我们的delegate（Fragment） on 2018/1/30.
 */

public class ExampleDelegate extends LatteDelegate {
    @Override
    public Object setLayout() {
        return R.layout.delegate_example;
    }

    @Override
    public void onBindView(@Nullable Bundle savedInstanceState, @NonNull View rootView) {
        testRestClient();
    }

    //    测试
    private void testRestClient() {
        RestClient.builder()  //此处返回-RestClientBuilder
                .url("http://news.baidu.com/")
                .loader(getContext())
//                .params("", "")
                .success(new ISuccess() {
                    @Override
                    public void onSuccess(String response) {
                        Toast.makeText(getContext(), response, Toast.LENGTH_LONG).show();
                    }
                })
                .failure(new IFailure() {
                    @Override
                    public void onFailure() {

                    }
                })
                .error(new IError() {
                    @Override
                    public void onError(int code, String msg) {

                    }
                })  //以上全部返回-RestClientBuilder
                .build()  //此处返回-RestClient
                .get();   //这是RestClient中方法

    }

}
